package kr.hkit.androidcomplete01.ch12;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerTest extends Activity {
	boolean mInitSpinner;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnertest);
		
		Spinner spin = (Spinner) findViewById(R.id.myspinner);
		spin.setPrompt("과일을 고르세요.");
		
		final ArrayAdapter<CharSequence> adspin = ArrayAdapter.createFromResource(this, 
				R.array.fruits, android.R.layout.simple_spinner_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spin.setAdapter(adspin);
		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(SpinnerTest.this, adspin.getItem(position) + "는 맛있다.", 
						Toast.LENGTH_LONG).show();
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
	}
}
